import http from '../../utils/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [
            {
            name: '今日推荐',
            id:0
        }, 
        {
            name: '热门下载',
            id:1
        }],
        activeHover:0,
        isShow1:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.recommentList(0)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    tabChange(e){
        let index = e.currentTarget.dataset.index
        let id= e.currentTarget.dataset.id
        if(id===1){
            this.recommentList(id)
        }else{
            this.recommentList()
        }
        this.setData({activeHover:index})
    },
    async recommentList(typeid){
        let that = this
        let options={}
        if(typeid==1){
            options={
                url:'/getUitype3',
                method:'POST',
                data:{type:1},
                header:{"content-type":"application/json;charset=UTF-8"}
            }
        }else{
            options={
                data:{type:0},
                url:'/getUitype3',
                method:'POST',
                header:{"content-type":"application/json;charset=UTF-8"}
            }
        }
        let res = await http(options)
        console.info(res)
        res.data.obj.map(item=>{
            let extea = item.itemname.substring(item.itemname.lastIndexOf('.')+1).toLowerCase()
            return Object.assign(item,{suffix:extea})
        })
        that.setData({recommentList:res.data.obj})
    },
    //资源详情跳转
    async linkDetail(e){
      let that = this
      let id = e.currentTarget.dataset.id
        let name = e.currentTarget.dataset.name
      let options={
          url:'/getVideoAuthority2',
          method:'POST',
          data:{id:id,userId:wx.getStorageSync('userInfo')?JSON.parse(wx.getStorageSync('userInfo')).id:'0',authorization:wx.getStorageSync('userInfo')?JSON.parse(wx.getStorageSync('userInfo')).authorization:''},
          header:{"content-type":"application/json;charset=UTF-8"}
      }
      let res = await http(options)
        if(res.data.code==0){
          wx.navigateTo({
            url: '/pages/resoucedetail/resoucedetail?id='+id+'&title='+name,
          })
        }else if(res.data.code==1){
          this.setData({isShow1:true})
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'error',
            duration: 2000
        })
        }
    },
    // 电子书城跳转
    ebooklink(){
        wx.navigateTo({
            url: '/pages/ebookIndex/ebookIndex',
        })
    }
    //  //资源详情跳转
    // linkDetail(e){
    //     let id = e.currentTarget.dataset.id
    //     let name = e.currentTarget.dataset.name
    //     wx.navigateTo({
    //     url: '/pages/resoucedetail/resoucedetail?id='+id+'&title='+name,
    //     })
    // }
})